From 3097749ea035fb5e638c90879946fa8c8306889e Mon Sep 17 00:00:00 2001 From: robertlipe Date: Mon, 11 Nov 2013 02:02:32 +0000 Subject: [PATCH] Plow through the remainder of our REALLY_MINIMAL targets with NEW_STRING. --- gpsbabel/delbin.cc | 90 +++++++++++++++++++++++++++++++++++----------- gpsbabel/garmin.cc | 51 +++++++++++++++----------- 2 files changed, 99 insertions(+), 42 deletions(-) diff --git a/gpsbabel/delbin.cc b/gpsbabel/delbin.cc index 1d3a1ac0a..f90f5744f 100644 --- a/gpsbabel/delbin.cc +++ b/gpsbabel/delbin.cc @@ -22,9 +22,6 @@ #include "defs.h" #include "src/core/xmltag.h" -#if REALLY_MINIMAL -ff_vecs_t delbin_vecs; -#else #include #define MYNAME "delbin" @@ -1096,7 +1093,11 @@ read_waypoints(void) const char* s = p->name + p->name_size; unsigned nn = le_readu16(s); if (notes_max < notes_i + nn) { +#if NEW_STRINGS +// This section needs a serious rethinking. +#else char* old = wp->notes; +#endif if (notes_max == 0) { notes_max = nn; } @@ -1104,15 +1105,18 @@ read_waypoints(void) notes_max += notes_max; } while (notes_max < notes_i + nn); wp->notes = (char*) xmalloc(notes_max); +#if NEW_STRINGS +#else if (old) { memcpy(wp->notes, old, notes_i); xfree(old); } +#endif } if (nn) { #if NEW_STRINGS -#warning gross code avoided. -abort(); + // Is this really what this code was trying to do? + wp->notes += QString::fromUtf8(s + 2, nn); #else memcpy(wp->notes + notes_i, s + 2, nn); #endif @@ -1198,7 +1202,11 @@ get_gc_notes(const waypoint* wp, int* symbol, char** notes, unsigned* notes_size if (0 == (wp->icon_descr.compare("Geocache Found"))) { gc_sym = 124; } +#if NEW_STRINGS + if (!wp->description.isEmpty()) { +#else if (wp->description) { +#endif gbfputs(wp->description, fd); if (!wp->gc_data->placer.isEmpty()) { gbfprintf(fd, " by %s", wp->gc_data->placer.toUtf8().data()); @@ -1378,20 +1386,29 @@ write_waypoint(const waypoint* wp) { message_t m; msg_waypoint_t* p; +#if NEW_STRINGS + QString name = wp->shortname; +#else const char* name = wp->shortname; - unsigned name_size; +#endif char* notes; + unsigned name_size; unsigned notes_size = 0; unsigned extended_notes_size = 0; - char* notes_freeable = NULL; + const char* notes_freeable = NULL; int symbol = -1; float elev = UNKNOWN_ELEV; char* pp; if (waypt_empty_gc_data(wp)) { +#if NEW_STRINGS + notes = xstrdup(wp->notes); + if (notes == NULL && wp->description.isEmpty() && wp->shortname != wp->description) { +#else notes = wp->notes; if (notes == NULL && wp->description && strcmp(wp->shortname, wp->description)) { - notes = wp->description; +#endif + notes = xstrdup(wp->description); } if (notes) { notes_size = strlen(notes) + 1; @@ -1399,7 +1416,11 @@ write_waypoint(const waypoint* wp) } else { get_gc_notes(wp, &symbol, ¬es, ¬es_size); notes_freeable = notes; +#if NEW_STRINGS + if (!wp->description.isEmpty()) { +#else if (wp->description) { +#endif name = mkshort(mkshort_handle, wp->description); } } @@ -1413,7 +1434,7 @@ write_waypoint(const waypoint* wp) } } - name_size = strlen(name) + 1; + name_size = strlen(CSTRc(name)) + 1; if (name_size > 255) { name_size = 255; } @@ -1438,7 +1459,7 @@ write_waypoint(const waypoint* wp) } p->symbol = symbol; p->name_size = name_size; - memcpy(p->name, name, name_size - 1); + memcpy(p->name, CSTRc(name), name_size - 1); p->name[name_size - 1] = 0; pp = p->name + name_size; m.size = (pp + 2 + notes_size) - (char*)p; @@ -1447,22 +1468,25 @@ write_waypoint(const waypoint* wp) pp[2] = 0; } else { le_write16(pp, notes_size); +#if NEW_STRINGS +#else if (notes) { memcpy(pp + 2, notes, notes_size - 1); pp[2 + notes_size - 1] = 0; } +#endif } add_to_batch(MSG_WAYPOINT_IN, &m); if (extended_notes_size) { - write_waypoint_notes(notes, extended_notes_size, name); + write_waypoint_notes(notes, extended_notes_size, CSTRc(name)); } if (notes_freeable) { xfree(notes_freeable); } if (global_opts.debug_level >= DBGLVL_L) { - warning(MYNAME ": wrote waypoint %u '%s'\n", waypoint_i, name); + warning(MYNAME ": wrote waypoint %u '%s'\n", waypoint_i, CSTRc(name)); } } @@ -1571,7 +1595,7 @@ read_track(route_head* track) m.size = MSG_REQUEST_TRACKS_SIZE; memset(m.data, 0, m.size); ((char*)m.data)[0] = 1; // Download single track - strcpy((char*)m.data + 1, track->rte_name); + strcpy((char*)m.data + 1, CSTRc(track->rte_name)); message_write(MSG_REQUEST_TRACKS, &m); if (get_batch(&msg_array, &msg_array_n)) { break; @@ -1793,14 +1817,22 @@ write_track_end(const route_head* track) if (waypoint_n == 0) { return; } +#if NEW_STRINGS + if (!track->rte_desc.isEmpty()) { +#else if (track->rte_desc) { - comment_size = strlen(track->rte_desc) + 1; +#endif + comment_size = strlen(CSTRc(track->rte_desc)) + 1; } message_init_size(&m, sizeof(msg_track_header_in_t) - 1 + comment_size); p = (msg_track_header_in_t*) m.data; memset(p->name, 0, sizeof(p->name)); +#if NEW_STRINGS + if (!track->rte_name.isEmpty()) { +#else if (track->rte_name) { - strncpy(p->name, track->rte_name, sizeof(p->name) - 1); +#endif + strncpy(p->name, CSTRc(track->rte_name), sizeof(p->name) - 1); } else { sprintf(p->name, "%lu", (long)wp_array[0]->GetCreationTime().toTime_t()); } @@ -1809,7 +1841,7 @@ write_track_end(const route_head* track) le_write16(p->color, track_color_index(track->line_color.bbggrr)); le_write16(p->comment_size, comment_size); if (comment_size) { - memcpy(p->comment, track->rte_desc, comment_size); + memcpy(p->comment, CSTRc(track->rte_desc), comment_size); } add_to_batch(MSG_TRACK_HEADER_IN, &m); write_track_points(); @@ -1920,8 +1952,13 @@ decode_route_point(const void* data) } if (fd->memlen) { gbfputc(0, fd); +#if NEW_STRINGS + // Reconsider if there's a less grubby way to do this. + wp->notes = QString::fromUtf8((const char*) fd->handle.mem, fd->memlen); +#else wp->notes = (char*) xmalloc(fd->memlen); memcpy(wp->notes, fd->handle.mem, fd->memlen); +#endif } gbfclose(fd); return wp; @@ -1944,7 +1981,7 @@ read_route(route_head* route) m.size = MSG_REQUEST_ROUTES_SIZE; memset(m.data, 0, m.size); ((char*)m.data)[0] = 1; // Download single route - strcpy((char*)m.data + 1, route->rte_name); + strcpy((char*)m.data + 1, CSTRc(route->rte_name)); message_write(MSG_REQUEST_ROUTES, &m); if (get_batch(&msg_array, &msg_array_n)) { break; @@ -2129,8 +2166,12 @@ write_route_points(void) shape_n = shape_point_counts[route_point_i]; le_write32(p->total, route_point_n); le_write32(p->index, route_point_i); +#if NEW_STRINGS + if (!wp->shortname.isEmpty()) { +#else if (wp->shortname) { - strncpy(p->name, wp->shortname, sizeof(p->name) - 1); +#endif + strncpy(p->name, CSTRc(wp->shortname), sizeof(p->name) - 1); } else { sprintf(p->name, "RPT%u", route_point_i); } @@ -2170,9 +2211,13 @@ write_route_begin(const route_head* track) static void write_route_point(const waypoint* wp) { - const char* s = wp->shortname; wp_array[waypoint_i++] = (waypoint*)wp; +#if NEW_STRINGS + if (wp->shortname.startsWith("SHP")) { +#else + const char* s = wp->shortname; if (s && s[0] == 'S' && s[1] == 'H' && s[2] == 'P' && s[3] >= '0' && s[3] <= '9') { +#endif shape_point_n++; shape_point_counts[route_point_n]++; } else { @@ -2192,8 +2237,12 @@ write_route_end(const route_head* route) message_init_size(&m, sizeof(msg_route_header_in_t)); p = (msg_route_header_in_t*) m.data; memset(p->name, 0, sizeof(p->name)); +#if NEW_STRINGS + if (!route->rte_name.isEmpty()) { +#else if (route->rte_name) { - strncpy(p->name, route->rte_name, sizeof(p->name) - 1); +#endif + strncpy(p->name, CSTRc(route->rte_name), sizeof(p->name) - 1); } else { sprintf(p->name, "%lu", (long)wp_array[0]->GetCreationTime().toTime_t()); } @@ -3358,4 +3407,3 @@ waypoint_symbol_index(const char* name) } // vi: ts=4 sw=4 noexpandtab -#endif diff --git a/gpsbabel/garmin.cc b/gpsbabel/garmin.cc index 5d5d384ec..a0d81268b 100644 --- a/gpsbabel/garmin.cc +++ b/gpsbabel/garmin.cc @@ -30,13 +30,6 @@ #include "garmin_fs.h" #include "garmin_device_xml.h" -#if REALLY_MINIMAL -// I just don't want to cope with this format right now. -ff_vecs_t garmin_vecs = { }; -#else - -#define SOON 1 - #define MYNAME "GARMIN" static const char* portname; static short_handle mkshort_handle; @@ -402,9 +395,7 @@ waypt_read(void) if (way[i]->time_populated) { wpt_tmp->SetCreationTime(way[i]->time); } -#if SOON garmin_fs_garmin_after_read(way[i], wpt_tmp, gps_waypt_type); -#endif waypt_add(wpt_tmp); GPS_Way_Del(&way[i]); } @@ -940,8 +931,8 @@ waypoint_prepare(void) * cleaning */ ident = mkshort(mkshort_handle, - global_opts.synthesize_shortnames ? src : - wpt->shortname); + global_opts.synthesize_shortnames ? CSTRc(src) : + CSTRc(wpt->shortname)); /* Should not be a strcpy as 'ident' isn't really a C string, * but rather a garmin "fixed length" buffer that's padded * to the end with spaces. So this is NOT (strlen+1). @@ -955,9 +946,13 @@ waypoint_prepare(void) // If we were explictly given a comment from GPX, use that. // This logic really is horrible and needs to be untangled. +#if NEW_STRINGS + if (!wpt->description.isEmpty() && +#else if (wpt->description && +#endif global_opts.smart_names && !wpt->gc_data->diff) { - memcpy(tx_waylist[i]->cmnt, wpt->description, strlen(wpt->description)); + memcpy(tx_waylist[i]->cmnt, CSTRc(wpt->description), strlen(CSTRc(wpt->description))); } else { if (global_opts.smart_names && wpt->gc_data->diff && wpt->gc_data->terr) { @@ -967,10 +962,10 @@ waypoint_prepare(void) snprintf(obuf, sizeof(obuf), "%s%d/%d %s", get_gc_info(wpt), wpt->gc_data->diff, wpt->gc_data->terr, - src); + CSTRc(src)); memcpy(tx_waylist[i]->cmnt, obuf, strlen(obuf)); } else { - memcpy(tx_waylist[i]->cmnt, src, strlen(src)); + memcpy(tx_waylist[i]->cmnt, CSTRc(src), strlen(CSTRc(src))); } } @@ -1013,9 +1008,7 @@ waypoint_prepare(void) if (categorybits) { tx_waylist[i]->category = categorybits; } -#if SOON garmin_fs_garmin_before_write(wpt, tx_waylist[i], gps_waypt_type); -#endif i++; } @@ -1049,8 +1042,12 @@ route_hdr_pr(const route_head* rte) { (*cur_tx_routelist_entry)->rte_num = rte->rte_num; (*cur_tx_routelist_entry)->isrte = 1; +#if NEW_STRINGS + if (!rte->rte_name.isEmpty()) { +#else if (rte->rte_name) { - strncpy((*cur_tx_routelist_entry)->rte_ident, rte->rte_name, +#endif + strncpy((*cur_tx_routelist_entry)->rte_ident, CSTRc(rte->rte_name), sizeof((*cur_tx_routelist_entry)->rte_ident)); } } @@ -1059,7 +1056,6 @@ static void route_waypt_pr(const waypoint* wpt) { GPS_PWay rte = *cur_tx_routelist_entry; - char* s, *d; /* * As stupid as this is, libjeeps seems to want an empty @@ -1091,9 +1087,15 @@ route_waypt_pr(const waypoint* wpt) // enforce that here, since jeeps doesn't. // // This was strncpy(rte->ident, wpt->shortname, sizeof(rte->ident)); + char* s, *d; d = rte->ident; +#if NEW_STRINGS + for (int idx = 0; idx < wpt->shortname.length(); idx++) { + int c = wpt->shortname[idx].toAscii(); +#else for (s = wpt->shortname; *s; s++) { int c = *s; +#endif if (receiver_must_upper && isalpha(c)) { c = toupper(c); } @@ -1146,8 +1148,12 @@ static void track_hdr_pr(const route_head* trk_head) { (*cur_tx_tracklist_entry)->ishdr = gpsTrue; +#if NEW_STRINGS + if (!trk_head->rte_name.isEmpty()) { +#else if (trk_head->rte_name) { - strncpy((*cur_tx_tracklist_entry)->trk_ident, trk_head->rte_name, sizeof((*cur_tx_tracklist_entry)->trk_ident)); +#endif + strncpy((*cur_tx_tracklist_entry)->trk_ident, CSTRc(trk_head->rte_name), sizeof((*cur_tx_tracklist_entry)->trk_ident)); (*cur_tx_tracklist_entry)->trk_ident[sizeof((*cur_tx_tracklist_entry)->trk_ident)-1] = 0; } else { sprintf((*cur_tx_tracklist_entry)->trk_ident, "TRACK%02d", my_track_count); @@ -1163,8 +1169,12 @@ track_waypt_pr(const waypoint* wpt) (*cur_tx_tracklist_entry)->lon = wpt->longitude; (*cur_tx_tracklist_entry)->alt = (wpt->altitude != unknown_alt) ? wpt->altitude : 1e25; (*cur_tx_tracklist_entry)->Time = wpt->GetCreationTime().toTime_t();; +#if NEW_STRINGS + if (!wpt->shortname.isEmpty()) { +#else if (wpt->shortname) { - strncpy((*cur_tx_tracklist_entry)->trk_ident, wpt->shortname, sizeof((*cur_tx_tracklist_entry)->trk_ident)); +#endif + strncpy((*cur_tx_tracklist_entry)->trk_ident, CSTRc(wpt->shortname), sizeof((*cur_tx_tracklist_entry)->trk_ident)); (*cur_tx_tracklist_entry)->trk_ident[sizeof((*cur_tx_tracklist_entry)->trk_ident)-1] = 0; } (*cur_tx_tracklist_entry)->tnew = wpt->wpt_flags.new_trkseg; @@ -1315,4 +1325,3 @@ d103_icon_number_from_symbol(const QString& s) } return 0; } -#endif -- 2.30.2